(function(window, undefined){
	vant.Toast.setDefaultOptions({ duration: 2000,allowMultiple:true });
	var YY = {
		ajax:function(option){//请求
			if(option.load){
				var loading = vant.Toast.loading({
					message: '加载中',
					forbidClick: true,
					duration: 0,
				});
			}
			
			$.ajax({
				url:option.url,    //请求的url地址
				dataType:"json",   //返回格式为json
				data:option.data || {},    //参数值
				type:option.method || "post",  //请求方式
				headers:option.headers || {},
                contentType: typeof (option.contentType)!=="undefined"?option.contentType :'application/x-www-form-urlencoded',
                processData:  typeof (option.processData)!=="undefined"?option.processData :"application/x-www-form-urlencoded",
				success:function(res){
					if(option.load){loading.clear();}
					if(res.code){
						option.success && option.success(res);
					}else{
						if(option.error){
							option.error(res);
						}else{
							vant.Toast(res.msg);
						}
					}
					option.complete && option.complete();
				},
				error:function(res,err){
					if(option.load){loading.clear();}
					//接口状态非200的情况下。
					console.log(JSON.stringify(res) + "," + JSON.stringify(err));
					vant.Toast("服务器开小差了，待会儿再试吧。");
					option.complete && option.complete();
				},
			});
		},
		chunk:function(array, size) {
            //获取数组的长度，如果你传入的不是数组，那么获取到的就是undefined
            var length = array.length
                //判断不是数组，或者size没有设置，size小于1，就返回空数组
            if (!length || !size || size < 1) {
                return []
            }
            //核心部分
            var index = 0 //用来表示切割元素的范围start
            var resIndex = 0 //用来递增表示输出数组的下标

            //根据length和size算出输出数组的长度，并且创建它。
            var result = new Array(Math.ceil(length / size))
                //进行循环
            while (index < length) {
                //循环过程中设置result[0]和result[1]的值。该值根据array.slice切割得到。
                result[resIndex++] = array.slice(index, (index += size))
            }

            //输出新数组
            return result;
        },
		getQueryVariable:function(name){
			var result = window.location.href.match(new RegExp("[\?\&]" + name + "=([^\&]+)", "i")); 
			if (result == null || result.length < 1) {
				return ""; 
			} 
			return result[1];
		},
		exit:function(){ //退出账号
			var  rs =window.confirm("确定要退出登录?");
			if (rs){
                location = "/index/user/login_out";
			}
		},
		rem:function(){ //REM单位适配
			var updateBaseFontSize = function() {
				var dWidth = document.documentElement.clientWidth>700?700:document.documentElement.clientWidth;
				var baseFontSize = dWidth * 100 / 750;
				$("html").attr("style",'font-size:' + (baseFontSize + 'px!important'));
			};
			window.addEventListener('resize', updateBaseFontSize);
			updateBaseFontSize();
		},
		os:function(){//返回系统
			var ua = navigator.userAgent,
			isWindowsPhone = /(?:Windows Phone)/.test(ua),
			isSymbian = /(?:SymbianOS)/.test(ua) || isWindowsPhone,
			isAndroid = /(?:Android)/.test(ua),
			isFireFox = /(?:Firefox)/.test(ua),
			isChrome = /(?:Chrome|CriOS)/.test(ua),
			isTablet = /(?:iPad|PlayBook)/.test(ua) || (isAndroid && !/(?:Mobile)/.test(ua)) || (isFireFox && /(?:Tablet)/.test(ua)),
			isPhone = /(?:iPhone)/.test(ua) && !isTablet,
			isPc = !isPhone && !isAndroid && !isSymbian;
			return {
				isTablet: isTablet,
				isPhone: isPhone,
				isAndroid: isAndroid,
				isPc: isPc
			};
		},
		initPage:function(){//判断一下当前环境是否需要跳转到手机或电脑页面去
			var path = location.pathname;
			console.log(path)
			// var search = location.search;
			if(path.indexOf("/index.html")==0){
				//当前是手机页面
				
				if (YY.os().isAndroid || YY.os().isPhone || YY.os().isTablet) {
					location = "/index-m.html";
				}
			}else{
				//当前是电脑页面
				if (YY.os().isPc) {
					location = "/index.html";
				}
			}
		},
		goBack:function(){
			history.go(-1);
		},
		getDateTimeStamp:function(dateStr) {//将字符串时间转换为时间戳
		    return Date.parse(dateStr.replace(/-/gi,"/"));
		},
		getDateDiff:function(dateStr) {//将时间转换为xx之前
		    var publishTime = YY.getDateTimeStamp(dateStr) / 1000,
		        d_seconds,
		        d_minutes,
		        d_hours,
		        d_days,
		        timeNow = parseInt(new Date().getTime()/1000),
		        d,
		        date = new Date(publishTime*1000),
		        Y = date.getFullYear(),
		        M = date.getMonth() + 1,
		        D = date.getDate(),
		        H = date.getHours(),
		        m = date.getMinutes(),
		        s = date.getSeconds();
		        //小于10的在前面补0
		        if (M < 10) {
		            M = '0' + M;
		        }
		        if (D < 10) {
		            D = '0' + D;
		        }
		        if (H < 10) {
		            H = '0' + H;
		        }
		        if (m < 10) {
		            m = '0' + m;
		        }
		        if (s < 10) {
		            s = '0' + s;
		        }

		    d = timeNow - publishTime;
		    d_days = parseInt(d/86400);
		    d_hours = parseInt(d/3600);
		    d_minutes = parseInt(d/60);
		    d_seconds = parseInt(d);

		    if(d_days > 0 && d_days < 2){
		        return d_days + '天前';
		    }else if(d_days <= 0 && d_hours > 0){
		        return d_hours + '小时前';
		    }else if(d_hours <= 0 && d_minutes > 0){
		        return d_minutes + '分钟前';
		    }else if (d_seconds < 60) {
		        if (d_seconds <= 0) {
		            return '刚刚';
		        }else {
		            return d_seconds + '秒前';
		        }
		    }else if (d_days >= 2 && d_days < 30){
		        return M + '-' + D + ' ' + H + ':' + m;
		    }else if (d_days >= 30) {
		        return Y + '-' + M + '-' + D + ' ' + H + ':' + m;
		    }
		},
		
		
		
		
		

	};/*YY - END*/
	
	
	//当是手机或电脑的时候分别调用不同的方法去适应。
	if (YY.os().isAndroid || YY.os().isPhone || YY.os().isTablet) {
		YY.initPage();
	    YY.rem();
	}else if (YY.os().isPc) {
		YY.initPage();
	    var eventTarget,supportTouch="ontouchstart"in window;document.createTouch||(document.createTouch=function(e,t,n,o,u,c,i){return new Touch(t,n,{pageX:o,pageY:u,screenX:c,screenY:i,clientX:o-window.pageXOffset,clientY:u-window.pageYOffset},0,0)}),document.createTouchList||(document.createTouchList=function(){for(var e=TouchList(),t=0;t<arguments.length;t++)e[t]=arguments[t];return e.length=arguments.length,e});var Touch=function(e,t,n,o,u){o=o||0,u=u||0,this.identifier=t,this.target=e,this.clientX=n.clientX+o,this.clientY=n.clientY+u,this.screenX=n.screenX+o,this.screenY=n.screenY+u,this.pageX=n.pageX+o,this.pageY=n.pageY+u};function TouchList(){var e=[];return e.item=function(e){return this[e]||null},e.identifiedTouch=function(e){return this[e+1]||null},e}var initiated=!1;function onMouse(e){return function(t){"mousedown"===t.type&&(initiated=!0),"mouseup"===t.type&&(initiated=!1),("mousemove"!==t.type||initiated)&&(("mousedown"===t.type||!eventTarget||eventTarget&&!eventTarget.dispatchEvent)&&(eventTarget=t.target),triggerTouch(e,t),"mouseup"===t.type&&(eventTarget=null))}}function triggerTouch(e,t){var n=document.createEvent("Event");n.initEvent(e,!0,!0),n.altKey=t.altKey,n.ctrlKey=t.ctrlKey,n.metaKey=t.metaKey,n.shiftKey=t.shiftKey,n.touches=getActiveTouches(t),n.targetTouches=getActiveTouches(t),n.changedTouches=createTouchList(t),eventTarget.dispatchEvent(n)}function createTouchList(e){var t=TouchList();return t.push(new Touch(eventTarget,1,e,0,0)),t}function getActiveTouches(e){return"mouseup"===e.type?TouchList():createTouchList(e)}function TouchEmulator(){window.addEventListener("mousedown",onMouse("touchstart"),!0),window.addEventListener("mousemove",onMouse("touchmove"),!0),window.addEventListener("mouseup",onMouse("touchend"),!0)}TouchEmulator.multiTouchOffset=75,supportTouch||new TouchEmulator;
	}
	window.$$ = window.YY = YY;
})(window, undefined);
